import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/guider_home";

export const select_shop_header_api = (showError = true) => {
  return Http.get<{ product_type: any[] }>(
    `/v3${baseUrl}/select_shop_header`
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const select_shop_items_api = (
  data: { type_id: number } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(
    `/v3${baseUrl}/select_shop_items`,
    data
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const guide_vip_order_mini_pay_api = (
  data: { order_id: string },
  showError = true
) => {
  return Http.post<any>(`${baseUrl}/guide_vip_order/mini_pay`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const offline_course_items_api = (
  data: MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(
    `${baseUrl}/offline_course/items`,
    data
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const offline_course_info_api = (
  data: { id: string },
  showError = true
) => {
  return Http.get<any>(`${baseUrl}/offline_course/info`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const offline_course_nationality_api = (showError = true) => {
  return Http.get<{ list: string[] }>(
    `${baseUrl}/offline_course/nationality`
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const offline_course_create_order_api = (
  data: any,
  showError = true
) => {
  return Http.post<{ order_id: string }>(
    `${baseUrl}/offline_course/create_order`,
    data
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const offline_course_order_mini_pay_api = (
  data: { order_id: string },
  showError = true
) => {
  return Http.post<any>(`${baseUrl}/offline_course_order/mini_pay`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const live_course_now_header_api = (showError = true) => {
  return Http.get<{ items: any[] }>(`${baseUrl}/live_course/now_header`).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const live_course_list_api = (
  data: { type: number } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(
    `${baseUrl}/live_course/list`,
    data
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const live_course_info_api = (
  data: { id: string },
  showError = true
) => {
  return Http.get<any>(`${baseUrl}/live_course/info`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const live_course_create_order_api = (
  data: { id: string },
  showError = true
) => {
  return Http.post<{ order_id: string }>(
    `${baseUrl}/live_course/create_order`,
    data
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const live_course_mini_pay_api = (
  data: { order_id: string },
  showError = true
) => {
  return Http.post<any>(`${baseUrl}/live_course/mini_pay`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};
